<?xml version="1.0" encoding="utf-8" ?>
<Recipe Name="SPCmdLet"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.microsoft.com/pag/gax-core"
    Bound="false">
	<DocumentationLinks>
		<Link Caption="MSDN: Windows PowerShell in the SharePoint Management Shell" Url="http://msdn.microsoft.com/en-us/library/ee536539.aspx" Kind="Documentation" />
		<Link Caption="MSDN: Key Concepts for Writing Cmdlets for the SharePoint Management Shell" Url="http://msdn.microsoft.com/en-us/library/ee534984.aspx" Kind="Documentation" />
		<Link Caption="MSDN: Development Guidelines for SharePoint Foundation Cmdlets" Url="http://msdn.microsoft.com/en-us/library/ee534968.aspx" Kind="Documentation" />
	</DocumentationLinks>
	<xi:include href="../../../TypeAlias.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
	<Caption>SharePoint CmdLet</Caption>
	<Description>Adds a SharePoint cmdlet to the project which does not use objects from the pipe (e.g. Start-MyCustomJob). The recipe creates the cmdlet class, the xml for the registration in SharePoint and a corresponding help file to store help information about the cmdlet.</Description>
	<HostData Priority="10">
		<Icon File="Help/Icons/icon_PowerShell.ico" />
		<CommandBar Menu="SPSFProjectPowerShell" />
		<spsf:MetaData
		  Visible="true"
		  BindingType="CustomizationReference"
		  BindingTypeTemplate="CustomizationReferenceTemplate"
		  TestType="BaseCustomizationRecipeRunner"
		  Enabled="true"
		  CreateVSTemplate="true"
		  NotSandboxSupported="true"
		  VSTemplateDefaultName="Start-MyCustomJob"
		  Category="PowerShell" xmlns:spsf="http://www.spalmblogger.de">
			<spsf:Authors>
				<spsf:Author>Torsten Mandelkow</spsf:Author>
			</spsf:Authors>
			<spsf:VersionHistory>
				<spsf:VersionHistoryEntry>1.0 Initial Recipe</spsf:VersionHistoryEntry>
			</spsf:VersionHistory>
			<spsf:WebPageContent>
				<![CDATA[The custom cmdlet can be used in powershell scripts (.ps1) to run adminstration jobs for instance, e.g. 'Start-MyCustomJob'.
Use command "Get-Help Start-MyCustomJob' to display a detailed help information.
Use command "Get-Command Start-MyCustomJob' to display general information.]]>
			</spsf:WebPageContent>
			<spsf:Test>
				<spsf:TestCases>
					<spsf:TestCase Name="DefaultCommand" Type="SolutionTestCase">
						<spsf:TestCaseArguments>
							<spsf:TestCaseArgument Name="SPCmdName">Start-MyCustomJob</spsf:TestCaseArgument>
						</spsf:TestCaseArguments>
					</spsf:TestCase>
				</spsf:TestCases>
			</spsf:Test>
		</spsf:MetaData>
	</HostData>
	<Arguments>

		<xi:include href="../../BaseArguments.include" parse="xml" xpointer="xmlns(p=http://schemas.microsoft.com/pag/gax-core) xpointer(/p:Arguments/*)" xmlns:xi="http://www.w3.org/2001/XInclude" />

		<Argument Name="SPCmdName" Required="true" >
			<ValueProvider Type="VisualStudioCreateItemName" MakeSafe="false" DefaultValue="Get-SPSiteByName" />
		</Argument>

		<Argument Name="SPCmdLetVerb" Required="true" >
			<ValueProvider Type="SplitStringProvider" RecipeArgument="SPCmdName" SplitChar="-" Index="0" />
		</Argument>
		<Argument Name="SPCmdLetNoun" Required="true" >
			<Converter Type="NamespaceStringConverter" />
			<ValueProvider Type="SplitStringProvider" RecipeArgument="SPCmdName" SplitChar="-" Index="1" />
		</Argument>
		<Argument Name="SPCmdLetVerbHelpDescription" Required="true" >
			<ValueProvider Type="Evaluator" Expression="Description of cmdlet" />
		</Argument>

		<Argument Name="SPCmdLetClassName" Required="true" >
			<ValueProvider Stage="OnBeforeActions" Type="Evaluator" Expression="SPCmdlet$(SPCmdLetVerb)$(SPCmdLetNoun)" />
		</Argument>
		<Argument Name="SPCmdLetFullClassName" Required="true" >
			<ValueProvider Stage="OnBeforeActions" Type="Evaluator" Expression="$(ProjectNamespace).PowerShell.$(SPCmdLetClassName)" />
		</Argument>
		<Argument Name="SPCmdLetRegistrationFileName" Required="true" >
			<ValueProvider Stage="OnBeforeActions" Type="Evaluator" Expression="$(SafeAppName).xml" />
		</Argument>
		<Argument Name="SPCmdLetHelpFileName" Required="true" >
			<ValueProvider Stage="OnBeforeActions" Type="Evaluator" Expression="$(SafeAppName).dll-help.xml" />
		</Argument>

		<Argument Name="GeneratedCommandName" >
			<ValueProvider Type="Evaluator" Expression="$(SPCmdLetVerb)-$(SPCmdLetNoun)" >
				<MonitorArgument Name="SPCmdLetVerb" />
				<MonitorArgument Name="SPCmdLetNoun" />
			</ValueProvider>
		</Argument>
		
	</Arguments>
	<GatheringServiceData>
		<Wizard xmlns="http://schemas.microsoft.com/pag/gax-wizards" SchemaVersion="1.0">
			<Pages>
				<Page Height="350">
					<Title>General Settings</Title>
					<Fields>
						<Field Label="Branding" ValueName="SPSFBranding" PanelType="SPALM.SharePointSoftwareFactory.Library.BrandingPanel, SPALM.SharePointSoftwareFactory.Library" />
						<Field ValueName="GeneratedCommandName" ReadOnly="true" Label="Generated Command">
							<Help>Optional String. Displays the final command</Help>
						</Field>
						<Field ValueName="SPCmdLetVerb" Label="Verb">
							<Help>Required String. Enter the verb e.g. "Start", "Stop", "Backup".</Help>
						</Field>
						<Field ValueName="SPCmdLetNoun" Label="Noun">
							<Help>Required String. Enter the operation or object type e.g. "SPSiteByName".</Help>
						</Field>
						<Field ValueName="SPCmdLetVerbHelpDescription" Label="Description">
							<Help>Required String. Enter the a short description of the cmdlet (used in help file).</Help>
						</Field>
					</Fields>
				</Page>				
			</Pages>
		</Wizard>
	</GatheringServiceData>
	<Actions CoordinatorServiceType="ConditionalCoordinator">

    <Action
		  Name="AddRegistrationFile"
		  Type="AddSPDataTemplateAction"
      SPDataName="$(SPCmdLetClassName)"
      SPDataCategory="PowerShellCmdLets"
      SPDataTemplate="Text\GenericSPData\SharePointProjectItem.spdata.t4"
		  TemplateFileName="Text\PowerShell\registration.xml.t4"
		  TargetFileName="$(SPCmdLetRegistrationFileName)"
      DeploymentType="RootFile"
		  DeploymentPath="Config\PowerShell\Registration"
		  Open="true">
      <Output Name="CreatedProjectItem" />
      <Output Name="CreatedProjectFolder" />
    </Action>

		<!-- add class for cmdlet -->
		<Action
		  Name="AddCmdLetCode"
		  Type="AddTemplateToItemAction"
		  DeploymentType="CustomCode"
		  Open="true"
		  TemplateFileName="Text\PowerShell\SPCmdLet\CmdLet.cs.t4"
		  TargetFileName="$(SPCmdLetClassName).cs">
			<Input Name="ParentProjectItem" ActionOutput="AddRegistrationFile.CreatedProjectItem" />
		</Action>
		
		<!-- Add help file -->
		<Action
		  Name="AddRegistrationHelpFile"
		  Type="AddTemplateToItemAction"
		  DeploymentType="RootFile"
		  DeploymentPath="Config\PowerShell\Help"
		  TemplateFileName="Text\PowerShell\help.xml.t4"
		  TargetFileName="$(SPCmdLetHelpFileName)">
      <Input Name="ParentProjectItem" ActionOutput="AddRegistrationFile.CreatedProjectItem" />
			<Output Name="CreatedProjectItem" />
		</Action>
		
		<Action
			Name="AddReference1"
			Type="AddReferenceToProject"
			ReferenceName="System.Management.Automation">
			<Input Name="Project" RecipeArgument="CurrentProject" />
		</Action>

		<Action
			Name="AddReference2"
			Type="AddReferenceToProject"
			ReferenceName="Microsoft.SharePoint.PowerShell">
			<Input Name="Project" RecipeArgument="CurrentProject" />
		</Action>

		<xi:include href="../../BaseFinalActions.include" parse="xml" xpointer="xmlns(p=http://schemas.microsoft.com/pag/gax-core) xpointer(/p:Actions/*)" xmlns:xi="http://www.w3.org/2001/XInclude" />

	</Actions>
</Recipe>